package cn.yx.user.controller.api;

import cn.yx.common.core.controller.BaseApiController;
import cn.yx.common.core.pojo.IdCond;
import cn.yx.common.core.pojo.ResponseVo;
import cn.yx.common.log.annotation.SysLog;
import cn.yx.user.controller.api.handler.UserAccountSentinelHandler;
import cn.yx.user.remote.dto.UserAccountRemoteDto;
import cn.yx.user.remote.service.UserAccountRemoteService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>用户账户API</p>
 *
 * @author Wgssmart
 */
@RestController
@RequestMapping("/api/user-account")
@RefreshScope
@Api(tags = "用户账户API")
public class UserAccountApiController implements BaseApiController {

    @DubboReference
    private UserAccountRemoteService userAccountRemoteService;

    @PostMapping("get-by-id")
    @SysLog(description = "根据id获取用户账户")
    @SentinelResource(value = "userAccountGetById",
            blockHandler = "getByIdBlockHandler", blockHandlerClass = {UserAccountSentinelHandler.class},
            fallback = "getByIdFallback", fallbackClass = {UserAccountSentinelHandler.class})
    @ApiOperation(value = "根据id获取用户账户")
    public ResponseVo<UserAccountRemoteDto> getOne(@RequestBody @Validated IdCond<Long> idCond) {
        return ResponseVo.ok(userAccountRemoteService.getOne(idCond.getId()));
    }

}
